<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" style="font-size: 10px;"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

	<title>TOP</title>
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <meta name="author" content="zhy">
	<style>
		*{
			margin: 0;
			padding: 0;
			outline: none;
		}
		.box{
			width: 790px;
			margin: 20px auto;
			font-size: 1.6rem
		}
		.box .title{
			font-size: 1.8rem;
			font-weight: 600;
			line-height: 30px;
			margin-bottom: 20px;
			margin-top: 20px
		}
		.box .table{
			width: 100%;
			border: 0
		}
		.table td{
			line-height: 30px
		}
		.colorb{
			color: #00499b
		}
		.colora{
			color: #595959
		}
		.color8{
			color: #808080
		}
		.ver{
			vertical-align: middle;
		}
		.mb20{
			margin-bottom: 20px
		}
		.basic img{
			display: inline-block;
			margin-right: 10px;
		}
		.form{
			margin-top: 20px;
			line-height: 40px
		}
		.form .card{
			width: 60px;
			height: 40px;
			border: 1px solid #808080;
			border-radius: 5px;
			/*float: right;*/
			padding-left: 15px;
			margin: 0 5px
		}
		.form select{
			width: 100px;
			height: 40px;
			border-radius: 5px;
			color: #808080;
			font-style: italic;
			padding: 0 5px;
			margin-left: 15px
		}
		.form .input-normal {
			height: 40px;
			border: 1px solid #808080;
			border-radius: 5px;
			padding-left: 15px;
			margin-left: 10px
		}
		.form .cvv{
			width: 50px;
			height: 40px;
			border: 1px solid #808080;
			border-radius: 5px;
			padding-left: 15px;
			margin-left: 10px
		}
		.form .cvv_lab{
			float: right;
		}
		.form button{
			width: 100%;
			height: 40px;
			border-radius: 5px;
			border: none;
			font-size: 16px;
			cursor: pointer;
		}
		.form .pay{
			background-color: #004e9d;
			color: white
		}
		.form .cancel{
			background-color: #ebebeb;
		}
		.footer{
			color: #999393;
			text-align: center;
			font-size: 14px;
			padding-bottom: 10px
		}
		@media screen and (max-width: 790px){
			.box{
				width: 90%
			}
			.form .card{
				width: 35px;
				height: 20px;
				padding-left: 0
			}
			.form select{
				width: 60px;
				height: 30px;
				margin-left: 6px
			}
			.form .cvv{
				width: 30px;
				height: 20px;
				padding-left: 0;
				margin-left: 0
			}
			.cvvImg{
				height: 20px
			}
			.table td{
				line-height: 22px
			}
		}
	</style>
</head>
<body>
	<div class="box">
		<div>

		</div>
		<div class="title">PAYMENT INFORMATION
			<img src="./top_static/top.png" class="ver">
		</div>
		<table class="table">
			<tbody>
				<tr>
					<td align="left" width="30%" class="colora">Payment Amount:</td>
					<td align="right" width="70%" class="colorb" id="mchTransAmount"></td>
				</tr>
				<tr>
					<td align="left" width="30%" class="colora">Order NO.:</td>
					<td align="right" width="70%" class="colorb" id="tradeNo"></td>
				</tr>
<!--				<tr>-->
<!--					<td align="left" width="30%" class="colora">Country:</td>-->
<!--					<td align="right" width="70%" class="colorb" id="cardCountry"></td>-->
<!--				</tr>-->
<!--				<tr>-->
<!--					<td align="left" width="30%" class="colora">State:</td>-->
<!--					<td align="right" width="70%" class="colorb" id="cardState"></td>-->
<!--				</tr>-->
<!--				<tr>-->
<!--					<td align="left" width="30%" class="colora">City:</td>-->
<!--					<td align="right" width="70%" class="colorb" id="cardCity"></td>-->
<!--				</tr>-->
<!--				<tr>-->
<!--					<td align="left" width="30%" class="colora">Address:</td>-->
<!--					<td align="right" width="70%" class="colorb" id="cardAddress"></td>-->
<!--				</tr>-->
				<tr>
					<td class="colora" colspan="2">Please confirm your order information.Once the payment is proceeded,we send an email to you,your email is <span id="grEmail" class="colorb"></span>.</td>
				</tr>
			</tbody>
		</table>

		<div class="title">BASIC INFORMATION</div>
		<div class="basic">
			<img src="./top_static/visa.png">
			<img src="./top_static/mastercard.png">
			<img src="./top_static/jcb.png">
		</div>

		<!-- 上线前需要修改这个地方 -->
		<input type="hidden" class="form-control" id="apiHost" value="/api/pay/payJumpConfirm">

		<form id="form" method="post" accept-charset="utf-8" class="form">

			<div class="mb20">
				<label class="color8">Card Number</label>
				<input type="text" id="one" name="segment1" class="card" pattern="[0-9]{4}" maxlength="4" tabindex="1" required=""> -
				<input type="text" id="two" name="segment2" class="card" pattern="[0-9]{4}" maxlength="4" tabindex="2" required=""> -
				<input type="text" id="three" name="segment3" class="card" pattern="[0-9]{4}" maxlength="4" tabindex="3" required=""> -
				<input type="text" id="four" name="segment4" class="card" pattern="[0-9]{4}" maxlength="4" tabindex="4" required="">
			</div>
			<div class="mb20">
				<label class="color8">Expiration Date</label>
				<select name="cardExpireM" required="">
					<option value="">Month</option>
					<option value="01">01</option>
					<option value="02">02</option>
					<option value="03">03</option>
					<option value="04">04</option>
					<option value="05">05</option>
					<option value="06">06</option>
					<option value="07">07</option>
					<option value="08">08</option>
					<option value="09">09</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
				</select>
				<select name="cardExpireY" required="">
					<option value="">Year</option>
					<option value="2021">2021</option>
					<option value="2022">2022</option>
					<option value="2023">2023</option>
					<option value="2024">2024</option>
					<option value="2025">2025</option>
					<option value="2026">2026</option>
					<option value="2027">2027</option>
					<option value="2028">2028</option>
					<option value="2029">2029</option>
					<option value="2030">2030</option>
					<option value="2031">2031</option>
					<option value="2032">2032</option>
					<option value="2033">2033</option>
					<option value="2034">2034</option>
					<option value="2035">2035</option>
					<option value="2036">2036</option>
					<option value="2037">2037</option>
					<option value="2038">2038</option>
					<option value="2039">2039</option>
					<option value="2040">2040</option>
					<option value="2041">2041</option>
					<option value="2042">2042</option>
					<option value="2043">2043</option>
					<option value="2044">2044</option>
					<option value="2045">2045</option>
				</select>

				<div class="cvv_lab">
					<label class="color8">CVV</label>
					<input type="text" name="cardCvv" class="cvv" required="" pattern="[0-9]{3}">
					<img src="./top_static/card.png" class="ver cvvImg">
				</div>

			</div>

			<div class="mb20">
				<label class="color8">Country</label>
				<input type="text" name="cardCountry" class="input-normal" required="">
				&nbsp;
				<label class="color8">State</label>
				<input type="text" name="cardState" class="input-normal" required="">
				&nbsp;
				<label class="color8">City</label>
				<input type="text" name="cardCity" class="input-normal" required="">
			</div>

			<div class="mb20">
				<label class="color8">Address</label>
				<input type="text" name="cardAddress" class="input-normal" style="width: 75%;" required="">
			</div>



			<button class="pay mb20" type="button" id="submit">PAY NOW</button>
		</form>

	</div>
	<div class="footer">
		<img src="./top_static/footer.png" class="ver">
		Secure credit card payment
	</div>

  <script type="text/javascript" src="./top_static/jquery.min.js"></script>
  <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script> -->
  <script type="text/javascript">
    	function IsPC(){
    	    var userAgentInfo =  navigator.userAgent;
    	    var reg = new RegExp("(Android|iPhone|SymbianOS|Windows Phone|iPad|iPod)","ig");
    	    var isPC =  !reg.test(userAgentInfo);
    	    return isPC
    	}
    	var initFontSize=function(){
    	    var n=document.getElementsByTagName("html")[0],
    	        e=document.documentElement.clientWidth;
    	    if(IsPC()){
    	        if(e>750){
    	            n.style.fontSize = "10px"
    	        }else{
    	            n.style.fontSize = e/750*10+"px"
    	        }
    	    }else{
    	        n.style.fontSize=e/750*10+"px";
    	    }
    	};
    	initFontSize();
    	window.onresize=function(){
    	    initFontSize()
    	};

		$(document).ready(function() {
			var javaEnabled=navigator.javaEnabled();
			$("#javaEnabled").val(navigator.javaEnabled());
			$("#colorDepth").val(screen.colorDepth);
			$("#screenHeight").val(screen.height);
			$("#screenWidth").val(screen.width);
			$("#timeZoneOffset").val(new Date().getTimezoneOffset());
			$("#userAgent").val(navigator.userAgent);
		});

		function moveNext(object,index){
			if(object.value.length == 4){
				document.forms[0].elements[index+1].focus();
			}
		}
		$("#one").bind('input porpertychange',function(){
			moveNext(document.getElementById('one'),0)
			});
		$("#two").bind('input porpertychange',function(){
			moveNext(document.getElementById('two'),1)
			});
		$("#three").bind('input porpertychange',function(){
			moveNext(document.getElementById('three'),2)
		    });
		$("#four").bind('input porpertychange',function(){
			moveNext(document.getElementById('four'),3)
			});

		function getQueryVariable(variable){
		   var query = window.location.search.substring(1)
		   var vars = query.split('&')
		   for (var i=0; i < vars.length; i++) {
		     var pair = vars[i].split('=')
		     if(pair[0] == variable) {
		      return decodeURIComponent(pair[1]);
		     }
		   }
		   return false
		}

		// 取值来设置一下文本
		let appId = getQueryVariable('appId');
		let tradeNo = getQueryVariable('tradeNo');
		let sign = getQueryVariable('sign');
		let mchUrl = getQueryVariable('mchUrl');
		let timestamp = getQueryVariable('timestamp');
		let mchTransAmount = getQueryVariable('mchTransAmount');
		let grEmail = getQueryVariable('grEmail');
		let returnUrl = decodeURIComponent(getQueryVariable('returnUrl'));

		$("#mchTransAmount").text(mchTransAmount);
		$("#tradeNo").text(tradeNo);
		$("#grEmail").text(grEmail);

		$("#cardCountry").text(getQueryVariable('cardCountry').replaceAll("+", " "));
		$("#cardState").text(getQueryVariable('cardState').replaceAll("+", " "));
		$("#cardCity").text(getQueryVariable('cardCity').replaceAll("+", " "));
		$("#cardAddress").text(getQueryVariable('cardAddress').replaceAll("+", " "));


		$("input[name='cardCountry']").val(getQueryVariable('cardCountry').replaceAll("+", " "));
		$("input[name='cardState']").val(getQueryVariable('cardState').replaceAll("+", " "));
		$("input[name='cardCity']").val(getQueryVariable('cardCity').replaceAll("+", " "));
		$("input[name='cardAddress']").val(getQueryVariable('cardAddress').replaceAll("+", " "));

    $("#submit").click(function() {
    	console.log($("#form").serialize());

    	if (!appId) {
    		alert('appId not exists');
    		return;
    	}
    	if (!tradeNo) {
    		alert('tradeNo not exists');
    		return;
    	}
    	if (!sign) {
    		alert('sign not exists');
    		return;
    	}
    	if (!mchUrl) {
    		alert('mchUrl not exists');
    		return;
    	}
    	if (!timestamp) {
    		alert('timestamp not exists');
    		return;
    	}
    	if ($("select[name='cardExpireY']").val() == '') {
    		alert('please choose card expire year');
    		return;
    	}
    	if ($("select[name='cardExpireM']").val() == '') {
    		alert('please choose card expire month');
    		return;
    	}
    	if ($("input[name='cardCvv']").val().length != 3) {
    		alert('please input card cvv');
    		return;
    	}
    	if ($("#one").val().length != 4 ||
    		$("#two").val().length != 4 ||
    		$("#three").val().length != 4 ||
    		$("#four").val().length != 4) {
    		alert('cardNo length is 16');
    		return;
    	}
    	var result = confirm("PAY NOW？");
    	if(result){
    		$("#submit").attr('disabled', 'true');
				$("#submit").css('backgroundColor', 'gray');
				$("#submit").text('Posting...');
    		$.ajax({
					url:      $("#apiHost").val(),
					method:   "post",
					data:     $("#form").serialize() + '&cardNo=' + $("#one").val() + $("#two").val() + $("#three").val() + $("#four").val() + "&appId=" + appId + "&tradeNo=" + tradeNo + "&mchUrl=" + mchUrl + "&timestamp=" + timestamp + "&sign=" + sign,
					timeout:  30000,
					success:  function (resp) {
						// 判断下，如果是有跳转支付地址，那就跳转了
						if (resp.code == 0) {
							if (resp.data.paymentUrl) {
								$("#submit").text("redirecting...");
								setTimeout(() => {
									window.open(resp.data.paymentUrl, "_blank");
								}, 2000);
							} else {
								$("#submit").text("PAY SUCCESS...");

								var paramStr = [];
								for (var k in resp.data) {
									paramStr.push(`${k}=${encodeURIComponent(resp.data[k])}`);
								}
								paramStr = paramStr.join("&");

								var url = returnUrl + (returnUrl.indexOf('?') >= 0 ? '&' : '?') + paramStr;

								setTimeout(() => {
									window.location.href = url;
								}, 2000);
							}
						} else {
							$("#submit").text('PAY NOW');
							$("#submit").removeAttr('disabled');
							$("#submit").css('backgroundColor', '#004e9d');
							alert(resp.message || 'request pay failed');
						}
					}, error: function (resp) {
						alert(resp.message || 'request pay failed');
						$("#submit").text('PAY NOW');
						$("#submit").removeAttr('disabled');
						$("#submit").css('backgroundColor', '#004e9d');
					}
				})
    		return true;
    	}else{
    		return false
    	}
    });
	</script>
</body></html>
